package Tree.Recursive;

import Utils.TreeNode;

/**
 * 左叶子之和
 * Lettcode 404: https://leetcode-cn.com/problems/sum-of-left-leaves/
 */
public class sumOfLeftLeaves {
    public int sumOfLeftLeaves(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (isLeaf(root.left)) {
            return root.left.val + sumOfLeftLeaves(root.right);
        }
        return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
    }

    private boolean isLeaf(TreeNode Node) {
        if (Node == null) {
            return false;
        }
        if (Node.left == null && Node.right == null) {
            return true;
        }
        return false;
    }
}
